package cn.fan.iot.mqtt;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 默认回调
 */
@Slf4j
@Component("default")
public class DefaultMqttCallBack extends AbsMqttCallBack {

//这里可引入redis来存上下线

    @Override
    protected void handleReceiveMessage(String topic, String message) {
//        fixme  数量上去后多线程解决  待修正完
        log.info("DefaultCallBack:topic={},message={}", topic, message);
        JSONObject mes = JSONObject.parseObject(message);
        String devno = mes.get("clientid").toString();

//        fixme  这里根据不同主题来 解析对应的设备进行号存取
        if (topic.contains("/connected")) {
//            redisConfig.getRedisTemplateByDb(10).opsForValue().set(devno, message);
        } else if (topic.contains("/disconnected")) {
//            redisConfig.getRedisTemplateByDb(10).delete(devno);
        }else if (topic.contains("/dev/coo")){
//            redisConfig.getRedisTemplateByDb(11).opsForValue().set(devno,message,10, TimeUnit.MINUTES);
        }
    }
}